﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    public class CityFloorEditor : MonoBehaviour
    {
        [Serializable]
        public class CityFloorEditorArea
        {
            [Header("解开区域ID")]
            public int areaId;
            // 根节点
            [Header("区域节点")]
            public Transform areaNode;
            // Wall节点
            [Header("Wall节点")]
            public Transform wallNode;
            // Ground节点
            [Header("Ground节点")]
            public Transform groundNode;
            // 解锁Ground节点
            [Header("解锁Floor节点")]
            public Transform unlockFloorNode;
            [Header("区域可占领特效")]
            public Transform containerEffect;
            // 解锁Ground特效节点
            [Header("解锁Floor特效节点")]
            public Transform unlockEffectNode;
            // 未解锁Ground节点
            [Header("未解锁Floor节点")]
            public Transform lockFloorNode;
            // 解锁时相机观察点
            [Header("解锁时摄像机观察点")]
            public GameObject lookAtPoint;
            // 解锁时相机距离
            [Header("解锁时摄像机距离，-1:保持不变")]
            [Range(-1, 999)]
            public int zoomDistance = -1;
            // 需要显示的围墙
            [Header("需要显示的围墙")]
            public List<GameObject> showWalls;
            [Header("解锁迷雾特效")]
            public GameObject unlockFogAni;
            [Header("区域解锁前水池")] 
            public GameObject unlockWater;

            public void SetVisible(bool visible)
            {
                if (unlockFloorNode != null)
                {
                    unlockFloorNode.SetActive(visible);
                }
                if (unlockEffectNode != null)
                {
                    unlockEffectNode.SetActive(visible);
                }
                if (lockFloorNode != null)
                {
                    lockFloorNode.SetActive(!visible);
                }
            }
            public void SetWallsVisible(bool visible)
            {
                for (int i = 0; i < showWalls.Count; ++i)
                {
                    showWalls[i].SetActive(visible);
                }
            }
        }
        
        [Header("导出路径")]
        [SerializeField]
        public string exportPath = "Assets/ResourcesAssets/City/Prefabs/CityRoot";

        [Header("Floor根节点")]
        public Transform rootFloorNode;
        
        [Header("区域数据")]
        public List<CityFloorEditorArea> areas;

        public void UnlockAreas(int maxAreaId)
        {
            for (int i = 0; i < areas.Count; ++i)
            {
                areas[i].SetWallsVisible(false);
                areas[i].SetVisible(false);
            }
            
            List<CityFloorEditorArea> unlockAreas = areas.FindAll(t => { return t.areaId <= maxAreaId; });
            for (int i = 0; i < unlockAreas.Count; ++i)
            {
                CityFloorEditorArea cityFloorEditorArea = unlockAreas[i];
                if (cityFloorEditorArea.areaId == maxAreaId)
                {
                    cityFloorEditorArea.SetWallsVisible(true);
                }
                cityFloorEditorArea.SetVisible(true);
            }
        }
    }
    
}